<?php

/**
 * This is the model class for table "tbl_manager".
 *
 * The followings are the available columns in table 'tbl_manager':
 * @property integer $id
 * @property string $user_id
 * @property string $user_name
 * @property string $email
 * @property string $password
 * @property string $login_time
 * @property string $grade
 * @property string $create_time
 * @property string $update_time
 * @property string $delete_time
 * @property string $status
 * @property integer $manager_id
 */

class Site extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Manager the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_estimate';
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}
	
	/**
	 *   返回一个时间段内的企业评论数   $type:  1=>最近30天  2=>最近6个月
	 */
	public function getEstimateLineNum($type)
	{
		$connection = Yii::app()->db;
		$command = $connection->createCommand();
		if($type == '1'){
			$sql = "select count(id) as count,date_format(create_time,'%m-%d')as time from tbl_estimate where date_format(create_time,'%Y-%m-%d')<=date_format(curdate(),'%Y-%m-%d') and date_format(create_time,'%Y-%m-%d')>=date_format(curdate() - interval 30 day,'%Y-%m-%d') group by time";
		}else{
			$sql = "select count(id) as count,date_format(create_time,'%Y-%m')as time from tbl_estimate where date_format(create_time,'%Y-%m')<=date_format(curdate(),'%Y-%m') and date_format(create_time,'%Y-%m')>=date_format(curdate() - interval 6 month,'%Y-%m') group by time";
		}
		$command->setText($sql);
		$rows = $command->queryAll();
		$list = array();
		if($rows)
		{
			foreach($rows as $key=>$row){
				$list[$row['time']] = $row['count'];
			}
		}
		return $list;
	}
}